<template>
  <div class="login-container">
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
      />
      <van-field
        v-model="password"
        type="password"
        name="pwd"
        label="密码"
        placeholder="密码"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
// import axios from "axios";
import { loginApi } from "@/api/userApi.js";
export default {
  name: "LoginPage",
  components: {},
  props: {},
  data() {
    return {
      username: "13888888888",
      password: "246810",
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    async onSubmit(values) {
      console.log("submit", values);

      try {
        const { data: res } = await loginApi({
          mobile: this.username,
          code: this.password,
        });
        this.$store.commit("saveToken", res.data);
        this.$router.push("/mine");
      } catch (error) {
        console.log("error:", error);
      }

      // axios
      //   .post("http://api-toutiao-web.itheima.net/app/v1_0/authorizations", {
      //     mobile: this.username,
      //     code: this.password,
      //   })
      //   .then((res) => {
      //     console.log("Res:", res);
      //   });

      // 发送 POST 请求
      // axios({
      //   method: "post",
      //   url: "http://api-toutiao-web.itheima.net/app/v1_0/authorizations",
      //   data: {
      //     mobile: this.username,
      //     code: this.password,
      //   },
      // }).then((res) => {
      //   console.log("Res:", res);
      // });
    },
  },
};
</script>

<style scoped lang="less"></style>
